package com.schoolhelper.model.dao.jsonparse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class YyzControllerJsonParser implements JsonParser {

    @Override
    public <T> List<T> getList(String responseData, Class<T> resultVoClass) {
        List<T> list = new ArrayList<>();

        JSONArray recordsArray = (JSONArray) JSONObject.parse(responseData);
        for (int i = 0; i < Objects.requireNonNull(recordsArray).size(); i++) {
            JSONObject data = recordsArray.getJSONObject(i);
            list.add(JSON.parseObject(String.valueOf(data), resultVoClass));
        }
        return list;
    }

    @Override
    public <T> T getOne(String responseData, Class<T> resultVoClass) {
        // todo
        return null;
    }

    @Override
    public boolean getCode(String responseData) {
        // 没有code
        return true;
    }

}
